<template>
  <!--患者信息 Header -->
  <a-card class="patient-info-header" :body-style="{ padding: '8px 12px' }">
    <div class="flex justify-between items-center">
      <slot name="prefix"></slot>
      <div class="flex items-center flex-1 overflow-x-auto">
        <div class="relative">
          <a-badge
            v-if="showBadge"
            :count="patientInfo?.czfz === '复诊' ? '复' : '初'"
            class="mr-4 header-badag"
            :offset="[0, 38]"
            :number-style="{ backgroundColor: patientInfo?.czfz === '复诊' ? '#fb923c' : '' }"
          >
            <a-avatar :size="48" :src="avatarMan" />
          </a-badge>

          <template v-if="isOutpatient">
            <div v-if="!isArmy && showInsurance" class="absolute right-[6px] top-[3px]">
              <RoundTag v-if="patientInfo.paymentTypeCode === 'YLFFFS001'" bg-color="#43e219">居</RoundTag>
              <RoundTag v-if="patientInfo.paymentTypeCode === 'YLFFFS002'" bg-color="#43e219">职</RoundTag>
              <RoundTag v-if="patientInfo.paymentTypeCode === 'YLFFFS003'" bg-color="#fb923c">自</RoundTag>
            </div>
          </template>
          <template v-else>
            <a-badge
              v-if="!isArmy && showInsurance && patientInfo?.isOwnExpense !== undefined"
              :count="patientInfo?.isOwnExpense ? '医' : '自'"
              :offset="[-25, -20]"
              :number-style="{ backgroundColor: patientInfo?.isOwnExpense ? '#43e219' : '#fb923c' }"
            />
          </template>

          <a-badge
            v-if="onlyShowBadge"
            count=""
            class="mr-4 header-badag"
            :offset="[0, 38]"
            :number-style="{ backgroundColor: patientInfo?.czfz === '复诊' ? '#fb923c' : '' }"
          >
            <a-avatar :size="48" :src="avatarMan" />
          </a-badge>
        </div>

        <div class="flex">
          <div class="ml-2 flex flex-col justify-around">
            <div class="text-xl font-semibold max-w-28 min-w-20 truncate" :class="[className]">
              <PatientPopoverCard v-if="patientInfo.brName" :patient-info="patientInfo" @change="onChange">
                {{ patientInfo.brName }}
              </PatientPopoverCard>
              <span v-else>姓名</span>
            </div>
            <div class="w-20">
              <span class="mr-4">{{ patientInfo?.brXb || '性别' }}</span>
              <span class="">{{ patientInfo?.brAge ? patientInfo?.brAge : '年龄' }}</span>
            </div>
          </div>
          <div v-if="showUserInfo" class="ml-2 flex flex-col justify-around w-[200px] truncate">
            <div class="flex justify-between">
              <div class="w-[100px] flex justify-start"><PhoneOutlined class="mr-2" />{{ patientInfo?.brMob || '手机号' }}</div>
              <a-tooltip v-if="showWork" :title="patientInfo.brZy?.length > 3 ? patientInfo?.brZy : ''">
                <div class="w-[80px] truncate">职业：{{ patientInfo?.brZy || '-' }}</div>
              </a-tooltip>
            </div>
            <div class="truncate" :title="patientInfo?.brJtdz"><EnvironmentOutlined class="mr-2" />{{ patientInfo?.brJtdz || '家庭地址' }}</div>
          </div>
        </div>
        <slot></slot>
      </div>
      <slot name="suffix"></slot>
    </div>
  </a-card>
</template>
<script setup>
import { EnvironmentOutlined, PhoneOutlined } from '@ant-design/icons-vue'
import avatarMan from '@/assets/images/avatar-man.png'
import PatientPopoverCard from '../PatientPopoverCard'

const emit = defineEmits(['change'])
defineProps({
  patientInfo: {
    type: Object,
    description: '病人信息',
    default: () => ({})
  },
  showBadge: {
    type: Boolean,
    default: true
  },
  showUserInfo: {
    type: Boolean,
    default: true
  },
  showInsurance: {
    type: Boolean,
    default: false
  },
  className: {
    type: String,
    default: 'text-primary'
  },
  showWork: {
    type: Boolean,
    default: true
  },
  onlyShowBadge: {
    type: Boolean,
    default: false
  },
  isOutpatient: {
    desc: '判断是门诊还是住院',
    type: Boolean,
    default: false
  }
})
const isArmy = getSystemConfig('NAVYHIS_MODE') === '1' //军用系统
const onChange = () => {
  emit('change')
}
</script>
<style lang="less" scoped>
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.patient-info-header {
  background-color: var(--secondary-color);
  :deep(.ant-badge-count) {
    background-color: var(--primary-color);
    // top: auto;
    // right: 6px;
    // bottom: 0;
    // box-shadow: none;
  }
  :deep(.ant-badge-not-a-wrapper) {
    width: 0;
  }
}
</style>
